package cn.licoy.wdog.core.service.hospital2.impl;
/**
 * @Author Sunne
 * @Date 18-8-14下午2:51
 * @Param emp-hospital
 * 高山仰止,景行行止.虽不能至,心向往之。
 **/

import cn.licoy.wdog.core.dto.hospital2.doctor.EarningsDto;
import cn.licoy.wdog.core.dto.hospital2.doctor.SelectEarningsDto;
import cn.licoy.wdog.core.entity.hospital2.Earnings;
import cn.licoy.wdog.core.entity.hospital2.StateNum;
import cn.licoy.wdog.core.mapper.hospital2.EarningsMapper;
import cn.licoy.wdog.core.service.hospital2.EarningsService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 *——————————————————————————女神保佑，永无bug——————————————————————
 *
 *                    .::::.
 *                  .::::::::.
 *                 :::::::::::  FUCK YOU
 *             ..:::::::::::'
 *           '::::::::::::'
 *             .::::::::::
 *        '::::::::::::::..
 *             ..::::::::::::.
 *           ``::::::::::::::::
 *            ::::``:::::::::'        .:::.
 *           ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *        .:::'       :::::  .:::::::::' ':::::.
 *       .::'        :::::.:::::::::'      ':::::.
 *      .::'         ::::::::::::::'         ``::::.
 *  ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 *                    '.:::::'                    ':'````..
 */

@Service
@Transactional
public class EarningsServiceImpl extends ServiceImpl<EarningsMapper, Earnings> implements EarningsService {

    @Override
    public SelectEarningsDto selectEarning(String uid) {
        List<Earnings> le = null;
        le = this.selectList(new EntityWrapper<Earnings>()
                .setSqlSelect("earning,from_name,order_body,state_num,create_date")
                .eq("doc_id",uid)
                .eq("state_num", StateNum.ok.code)
                .eq("status","1")
        );
        int sum = 0;
        List<EarningsDto> led = new ArrayList<>();
        for (int i = 0;  i<le.size();){
            String earing = le.get(i).getEarning();
            int ear = Integer.parseInt(earing);
            EarningsDto dto = new EarningsDto();
            dto.setOrderBody(le.get(i).getOrderBody());
            dto.setFromName(le.get(i).getFromName());
            dto.setEarning(le.get(i).getEarning());
            dto.setEaringDate(le.get(i).getCreateDate());
            led.add(dto);
            sum = sum + ear;
            i++;
        }
        SelectEarningsDto se = new SelectEarningsDto();
        se.setEarningsDtoList(led);
        //总收益
        se.setSumEarnings(Integer.toString(sum));
        return se;
    }
}
